package com.echovin.esb.gateway.mapper;

import com.echovin.esb.gateway.model.GatewayServer;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GatewayServiceMapper {
    @Select("select * from GATEWAY_SERVICE")
    List<GatewayServer> getGatewayService();

    @SelectKey(keyProperty = "record.id", resultType = String.class, before = true,
            statement = "select replace(uuid(), '-', '')")
    @Options(keyProperty = "record.id", useGeneratedKeys = true)
    @Insert("insert into GATEWAY_SERVICE(ID,GROUP_ID,SERVICE_NAME,PATH,ROUTE_RULE,PROTOCOL,REMARK,CREATER,CREATE_TIME) " +
            "values(#{record.id},#{record.groupId},#{record.serviceName},#{record.path},#{record.routeRule},#{record.protocol},#{record.remark},#{record.creater},#{record.createTime})")
    int insert(@Param("record") GatewayServer record);

    @Update("update GATEWAY_SERVICE set IS_DELETE = 1, UPDATER = #{record.updater}, UPDATE_TIME = #{record.updateTime} where ID = #{record.id}")
    int delete(GatewayServer record);

    @Update("update GATEWAY_SERVICE set SERVICE_NAME = #{record.serviceName}, PATH = #{record.path}, ROUTE_RULE = #{record.routeRule}, PROTOCOL = #{record.protocol}, REMARK = #{record.remark}, UPDATER = #{record.updater}, UPDATE_TIME = #{record.updateTime} where ID = #{record.id}")
    int update(GatewayServer record);
}
